﻿using System;
using System.Collections.Generic;
using System.Text;
using Vbyte.SharpOrm.SqlDb;

namespace Vbyte.SharpOrm.Adapter
{
    /// <summary>
    /// Microsoft Jet SQL的Sql构建适配(MS Access)
    /// </summary>
    public class JetSqlBuilderAdapter : SqlBuilderBase
    {
        /// <summary>
        /// 是否实现了约束的表达式语句构建
        /// </summary>
        /// <returns></returns>
        public override bool HasImplementConstraintExp()
        {
            return true;
        }

        /// <summary>
        /// 构建SQL约束表达式
        /// </summary>
        /// <param name="build">实现了约束表达式构建的实例</param>
        /// <param name="dbOwner">数据库所有者占位前缀</param>
        /// <param name="tableName">数据库表名</param>
        /// <param name="columnName">涉及到的列名</param>
        /// <returns>最终的约束表达式语句</returns>
        public override string BuildConstraintExpression(ISqlConstraintExpBuild build, string dbOwner, string tableName, string columnName)
        {
            if (build == null)
            {
                throw new NullReferenceException("SQL约束构建实现不能为null!");
            }
            string exp = build.GetExpression(dbOwner, tableName, columnName);
            exp = exp.Replace("{DBOWNER}", "");
            return exp;
        }
    }

}
